package com.bw.controller;

import com.alibaba.fastjson.JSONObject;
import com.bw.pojo.Role;
import com.bw.pojo.User;
import com.bw.service.impl.UserRoleServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/userRole/*")
public class UserRoleController extends BaseController{
    UserRoleServiceImpl service = new UserRoleServiceImpl();
    //1.查看 （查询所有角色+根据用户id回显）
    protected void findRole(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String uid = req.getParameter("uid");
        List<Role> list = service.findRole(uid);
        resp.getWriter().println(JSONObject.toJSONString(list));
    }


    //2.修改dasfafdsfsdaf
    protected void updUserRole(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.取值 2.转对象 3.调用Service 4.响应客户
        String reqInfos = req.getParameter("reqInfos");
        User user = JSONObject.parseObject(reqInfos, User.class);
        service.updUserRole(user);
        resp.getWriter().println(JSONObject.toJSONString(200));
    }
}
